
package com.offer.leetcode;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Arrays;
import java.util.List;
import java.util.PriorityQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.stream.Collector;
import java.util.stream.Collectors;

import com.google.common.collect.Lists;

/**
 * Solution59
 */
public class Solution59 {

    public static void main(String[] args) {
        // Solution59 s = new Solution59();
        int[] nums = {1,3,-1,-3,5,3,6,7};

        // int[] result = s.maxSlidingWindow(nums, 3);

        // Arrays.stream(result).forEach(System.out::println);


        List<Integer> list = Lists.newArrayList(1, 2,3);

        int[] tmp = list.stream()
                .mapToInt(Integer::intValue).toArray();
        
    }

    public int[] maxSlidingWindow(int[] nums, int k) {

        if (nums == null) {
            return nums;
        }

        int count = nums.length - k + 1;
        int[] result = new int[count];
        // 1. 采用优先级队列
        PriorityQueue<Integer> maxHeap = new PriorityQueue<>(k, (a, b) -> -(a - b));
        int index = 0;
        for (int i = 0; i < nums.length; ++i) {

            if (maxHeap.size() < k) {
                maxHeap.offer(nums[i]);
            } else {
                result[index++] = maxHeap.poll();
                maxHeap.offer(nums[i]);
            }
        }
        

        Proxy.newProxyInstance(Solution59.class.getClassLoader(), Solution59.class.getInterfaces(),new InvocationHandler(){
        
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                // TODO Auto-generated method stub
                return null;
            }
        } );

        StringBuilder sb = new StringBuilder("abcdefg");
        // sb.capacity();
        System.out.println(sb.reverse().toString());
       
       Arrays.stream(nums).boxed().collect(Collectors.toList());


        return result;

    }
}